package uk.co.hs.web.security.authentication;

import java.util.Collection;
import java.util.Map;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.authority.SimpleGrantedAuthority;

/**
 * UtilisoftAuthentication.
 */
public class UtilisoftAuthentication implements Authentication
{
  private static final long serialVersionUID = 1L;

  private Object mCredentials;
  private Object mDetails;
  private Object mPrincipal;
  private String mName;
  private boolean mAuthenticated;
  private Map<String, Boolean> mAllowedURLS;
  private Collection<SimpleGrantedAuthority> mAuthorities;

  /**
   * UtilisoftAuthentication.
   *
   * @param aAuthentication
   * @param aAllowedURLs
   */
  @SuppressWarnings("unchecked")
  public UtilisoftAuthentication(Authentication aAuthentication,
  															 Map<String, Boolean> aAllowedURLs)
  {
    mCredentials = aAuthentication.getCredentials();
    mDetails = aAuthentication.getDetails();
    mPrincipal = aAuthentication.getPrincipal();
    mName = aAuthentication.getName();
    mAuthenticated = aAuthentication.isAuthenticated();
    mAuthorities = (Collection<SimpleGrantedAuthority>) aAuthentication.getAuthorities();
    mAllowedURLS = aAllowedURLs;
  }

  /**
   * @see java.security.Principal
   * #getName()
   * {@inheritDoc}
   */
  public String getName()
  {
    return mName;
  }

  /**
   * @see org.springframework.security.core.Authentication
   * #getAuthorities()
   * {@inheritDoc}
   */
  public Collection<SimpleGrantedAuthority> getAuthorities()
  {
    return mAuthorities;
  }

  /**
   * @see org.springframework.security.core.Authentication
   * #getCredentials()
   * {@inheritDoc}
   */
  public Object getCredentials()
  {
    return mCredentials;
  }

  /**
   * @see org.springframework.security.core.Authentication
   * #getDetails()
   * {@inheritDoc}
   */
  public Object getDetails()
  {
    return mDetails;
  }

  /**
   * @see org.springframework.security.core.Authentication
   * #getPrincipal()
   * {@inheritDoc}
   */
  public Object getPrincipal()
  {
    return mPrincipal;
  }

  /**
   * @see org.springframework.security.core.Authentication
   * #isAuthenticated()
   * {@inheritDoc}
   */
  public boolean isAuthenticated()
  {
    return mAuthenticated;
  }

  /**
   * @see org.springframework.security.core.Authentication
   * #setAuthenticated(boolean)
   * {@inheritDoc}
   */
  public void setAuthenticated(boolean aAuthenticated) throws IllegalArgumentException
  {
    mAuthenticated = aAuthenticated;
  }

  public void setAuthorities(Collection<SimpleGrantedAuthority> aAuthorities)
  {
    mAuthorities = aAuthorities;
  }

	/**
	 * @return the allowedURLS
	 */
	public Map<String, Boolean> getAllowedURLS()
	{
		return mAllowedURLS;
	}

	/**
	 * @param aAllowedURLS the allowedURLS to set
	 */
	public void setAllowedURLS(Map<String, Boolean> aAllowedURLS)
	{
		mAllowedURLS = aAllowedURLS;
	}
}
